from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.QtGui import *

from ui_form import Ui_MagicBook

class Form(QDialog, Ui_MagicBook):
    '''
    Implementation of logic for a window
    '''
    def __init__(self, parent = None):
	QDialog.__init__(self, parent)
	self.setupUi(self)
	self.connect(self.pagesInBlock, SIGNAL("valueChanged(int)"), self.checkNumber)
	self.OK = False

    def show(self):
	self.fNameLabel.setText(self.filename)
	QDialog.show(self)

    def checkNumber(self):
	'''
	Function, which checks that number of pages is divisible by four
	'''
	value = self.pagesInBlock.value()
	if value % 4 > 0:
	    self.pagesInBlock.setValue( int(value / 4) * 4 )

    def accept(self):
	'''
	Stores user input into variables and closes dialog
	'''
	self.OK        = True
	self.pages     = self.pagesInBlock.value()
	self.numbering = self.pageNumbers.isChecked()
	QDialog.accept(self)


    # We store here parameters, which user has defined:
    # pages	- number of pages
    # numbering - whether we need page numbering
